﻿using System;
using System.Collections.Generic;
using UILib;
using UnityEngine;
using XMainClient.UI.UICommon;
using XUpdater;
using XUtliPoolLib;

namespace XMainClient
{
	// Token: 0x02000BCC RID: 3020
	internal class BroadcastDlg : DlgBase<BroadcastDlg, BroadcastBehaviour>
	{
		// Token: 0x17003075 RID: 12405
		// (get) Token: 0x0600AC2D RID: 44077 RVA: 0x001FA450 File Offset: 0x001F8650
		public override string fileName
		{
			get
			{
				return "GameSystem/BroadcastDlg";
			}
		}

		// Token: 0x17003076 RID: 12406
		// (get) Token: 0x0600AC2E RID: 44078 RVA: 0x001FA468 File Offset: 0x001F8668
		public override bool autoload
		{
			get
			{
				return true;
			}
		}

		// Token: 0x17003077 RID: 12407
		// (get) Token: 0x0600AC2F RID: 44079 RVA: 0x001FA47C File Offset: 0x001F867C
		public override bool isHideChat
		{
			get
			{
				return false;
			}
		}

		// Token: 0x0600AC30 RID: 44080 RVA: 0x001FA490 File Offset: 0x001F8690
		protected override void Init()
		{
			base.Init();
			base.uiBehaviour.m_lblCamera.SetText(XStringDefineProxy.GetString("BROAD_CAMERA_OPEN"));
			GameObject tpl = base.uiBehaviour.loopScrool.GetTpl();
			bool flag = tpl != null && tpl.GetComponent<BroadBarrageItem>() == null;
			if (flag)
			{
				tpl.AddComponent<BroadBarrageItem>();
			}
		}

		// Token: 0x0600AC31 RID: 44081 RVA: 0x001FA4F8 File Offset: 0x001F86F8
		public override void RegisterEvent()
		{
			base.RegisterEvent();
			base.uiBehaviour.m_btnBarrage.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnEndClick));
			base.uiBehaviour.m_btnCamera.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnCameraClick));
			base.uiBehaviour.m_btnClose.RegisterClickEventHandler(new ButtonClickEventHandler(this.ClosePanel));
			base.uiBehaviour.m_btnShare.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnShareClick));
		}

		// Token: 0x0600AC32 RID: 44082 RVA: 0x001FA584 File Offset: 0x001F8784
		protected override void OnShow()
		{
			base.OnShow();
			this.timer = XSingleton<XTimerMgr>.singleton.SetTimer(0.5f, new XTimerMgr.ElapsedEventHandler(this.TimerShow), null);
			this.originPos = DlgBase<BroadMiniDlg, BroadcastMiniBehaviour>.singleton.GetIconPos();
			this.isClosing = false;
			base.uiBehaviour.transform.localPosition = Vector3.zero;
			base.uiBehaviour.transform.localScale = Vector3.one;
		}

		// Token: 0x0600AC33 RID: 44083 RVA: 0x001FA5FE File Offset: 0x001F87FE
		protected override void OnUnload()
		{
			XSingleton<XTimerMgr>.singleton.KillTimer(this.timer);
			base.OnUnload();
		}

		// Token: 0x0600AC34 RID: 44084 RVA: 0x001FA61C File Offset: 0x001F881C
		public void Push(string _nickname, string _content)
		{
			BroadNode item = default(BroadNode);
			item.nickname = _nickname;
			item.content = _content;
			bool flag = this.barrages.Count > this.max_count;
			if (flag)
			{
				this.barrages.RemoveRange(0, this.barrages.Count - this.max_count);
			}
			this.barrages.Add(item);
		}

		// Token: 0x0600AC35 RID: 44085 RVA: 0x001FA687 File Offset: 0x001F8887
		private void TimerShow(object o)
		{
			this.ShowList();
			this.timer = XSingleton<XTimerMgr>.singleton.SetTimer(0.4f, new XTimerMgr.ElapsedEventHandler(this.TimerShow), null);
		}

		// Token: 0x0600AC36 RID: 44086 RVA: 0x001FA6B4 File Offset: 0x001F88B4
		public void ShowList()
		{
			bool flag = base.IsVisible();
			if (flag)
			{
				List<LoopItemData> list = new List<LoopItemData>();
				string b = string.Empty;
				for (int i = 0; i < this.barrages.Count; i++)
				{
					BarrageMsg barrageMsg = new BarrageMsg();
					barrageMsg.LoopID = XSingleton<XCommon>.singleton.XHash(this.barrages[i].content + i);
					barrageMsg.nickname = this.barrages[i].nickname;
					barrageMsg.content = this.barrages[i].content;
					list.Add(barrageMsg);
					b = XSingleton<XCommon>.singleton.StringCombine(barrageMsg.nickname, barrageMsg.content);
				}
				bool flag2 = string.IsNullOrEmpty(this.lastCahceMsg) || this.lastCahceMsg != b;
				if (flag2)
				{
					base.uiBehaviour.loopScrool.Init(list, new DelegateHandler(this.RefreshItem), null, 1, false);
				}
				bool flag3 = this.barrages != null && this.barrages.Count > 0;
				if (flag3)
				{
					int index = this.barrages.Count - 1;
					this.lastCahceMsg = XSingleton<XCommon>.singleton.StringCombine(this.barrages[index].nickname, this.barrages[index].content);
				}
			}
		}

		// Token: 0x0600AC37 RID: 44087 RVA: 0x001FA834 File Offset: 0x001F8A34
		public override void OnUpdate()
		{
			base.OnUpdate();
			bool flag = this.isClosing;
			if (flag)
			{
				base.uiBehaviour.gameObject.transform.localPosition = Vector3.Lerp(Vector3.zero, this.originPos, (Time.time - this.closeTime) / this.closeDuration);
				base.uiBehaviour.gameObject.transform.localScale = Vector3.Lerp(Vector3.one, 0.1f * Vector3.one, (Time.time - this.closeTime) / this.closeDuration);
				bool flag2 = Time.time - this.closeTime >= this.closeDuration;
				if (flag2)
				{
					this.isClosing = false;
					this.SetVisible(false, true);
					DlgBase<BroadMiniDlg, BroadcastMiniBehaviour>.singleton.Show(true);
				}
			}
		}

		// Token: 0x0600AC38 RID: 44088 RVA: 0x001FA90C File Offset: 0x001F8B0C
		private void RefreshItem(ILoopItemObject item, LoopItemData data)
		{
			BarrageMsg barrageMsg = data as BarrageMsg;
			bool flag = barrageMsg != null;
			if (flag)
			{
				GameObject obj = item.GetObj();
				bool flag2 = obj != null;
				if (flag2)
				{
					BroadBarrageItem component = obj.GetComponent<BroadBarrageItem>();
					bool flag3 = component != null;
					if (flag3)
					{
						component.Refresh(barrageMsg.nickname, barrageMsg.content);
					}
				}
			}
			else
			{
				XSingleton<XDebug>.singleton.AddErrorLog("BroadBarrageItem info is null", null, null, null, null, null);
			}
		}

		// Token: 0x0600AC39 RID: 44089 RVA: 0x001FA980 File Offset: 0x001F8B80
		private bool OnEndClick(IXUIButton btn)
		{
			//XSingleton<XUpdater.XUpdater>.singleton.XBroadCast.StopBroadcast();
			this.ClosePanel(btn);
			return true;
		}

		// Token: 0x0600AC3A RID: 44090 RVA: 0x001FA9AC File Offset: 0x001F8BAC
		private bool OnCameraClick(IXUIButton btn)
		{
			bool flag = BroadcastDlg.isCameraOpen;
			if (flag)
			{
				//XSingleton<XUpdater.XUpdater>.singleton.XBroadCast.ShowCamera(false);
				BroadcastDlg.isCameraOpen = false;
				base.uiBehaviour.m_lblCamera.SetText(XStringDefineProxy.GetString("BROAD_CAMERA_OPEN"));
			}
			else
			{
// 				bool flag2 = XSingleton<XUpdater.XUpdater>.singleton.XBroadCast.ShowCamera(true);
// 				if (flag2)
// 				{
// 					BroadcastDlg.isCameraOpen = true;
// 					base.uiBehaviour.m_lblCamera.SetText(XStringDefineProxy.GetString("BROAD_CAMERA_CLOSE"));
// 				}
			}
			return true;
		}

		// Token: 0x0600AC3B RID: 44091 RVA: 0x001FAA38 File Offset: 0x001F8C38
		private bool OnShareClick(IXUIButton btn)
		{
			XSingleton<XDebug>.singleton.AddGreenLog("sharebtn click", null, null, null, null, null);
			this.ClosePanel(btn);
			return true;
		}

		// Token: 0x0600AC3C RID: 44092 RVA: 0x001FAA68 File Offset: 0x001F8C68
		private bool ClosePanel(IXUIButton btn)
		{
			bool flag = !this.isClosing;
			if (flag)
			{
				this.closeTime = Time.time;
				this.isClosing = true;
			}
			return true;
		}

		// Token: 0x040040CF RID: 16591
		private static bool isCameraOpen = false;

		// Token: 0x040040D0 RID: 16592
		public readonly int max_count = 40;

		// Token: 0x040040D1 RID: 16593
		public List<BroadNode> barrages = new List<BroadNode>();

		// Token: 0x040040D2 RID: 16594
		public string lastCahceMsg = string.Empty;

		// Token: 0x040040D3 RID: 16595
		private Vector3 originPos = Vector3.zero;

		// Token: 0x040040D4 RID: 16596
		private float closeTime = 0f;

		// Token: 0x040040D5 RID: 16597
		private float closeDuration = 0.3f;

		// Token: 0x040040D6 RID: 16598
		private bool isClosing = false;

		// Token: 0x040040D7 RID: 16599
		private uint timer = 0U;
	}
}
